package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.pojo.vo.LendDetailVO;
import com.atguigu.srb.core.service.LendService;
import com.atguigu.srb.result.ResponseVo;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */
@Api(tags = "标的 接口")
@RestController
@RequestMapping("/admin/core/lend")
public class AdminLendController {
    @Resource
    private LendService lendService;
    @ApiOperation("查询标的详情")
    @GetMapping("{id}")
    public ResponseVo getLendDetailById(@PathVariable("id") Long lendId){
        LendDetailVO lendDetailVO = lendService.getLendDetailById(lendId);
        return ResponseVo.ok().addData("item",lendDetailVO);
    }
    @ApiOperation("查询标的列表")
    @GetMapping
    public ResponseVo list(){
        List<Lend> list = lendService.getLendList();
        return ResponseVo.ok().addData("items",list);
    }
    @ApiOperation("标的发布")
    @PutMapping("/publish/{id}")
    public ResponseVo publish(@PathVariable("id")Long id){
        Lend lend = new Lend();
        lend.setId(id);
        lend.setPublishDate(new Date());
        lend.setCheckAdminId(Long.parseLong(IdWorker.getIdStr()));
        lend.setStatus(1);  // 募资中
        lend.setCheckTime(new Date());
        lendService.updateById(lend);
        return ResponseVo.ok().message("发布成功");
    }
}

